#ifndef PIPEDISPLAYOPENGLWIDGET_H
#define PIPEDISPLAYOPENGLWIDGET_H

#include "scene/mousecontroller.h"
#include "scene/rightmousecontroller.h"

#include <QEvent>
#include <QOpenGLWidget>
#include <QOpenGLExtraFunctions>
#include <QOpenGLFunctions_3_3_Core>
#include <QOpenGLShader>
#include <QOpenGLShaderProgram>

/** 专门用于后处理管道展示的对象，继承自QOpenGLWidget */
class PipeDisplayOpenGLWidget : public QOpenGLWidget,
        protected QOpenGLFunctions_3_3_Core
{
public:
    PipeDisplayOpenGLWidget(QWidget *parent = nullptr);
    ~PipeDisplayOpenGLWidget();
    virtual QObject *getScene() {
        return scene;
    }

protected:
    virtual void initializeGL();
    virtual void resizeGL(int w, int h);
    virtual void paintGL();
    virtual void setSingleAttribPosition(GLuint attribPosition, int size, GLfloat *positions);
private:
    /** 是否被加载 */
    boolean installed = false;
    /** 着色器程序 */
    QOpenGLShaderProgram shaderProgram;
    /** 计时器 */
    QTimer *m_pTimer = nullptr;
    /** WSY自己的场景对象 */
    QObject *scene;
    /** 专用的鼠标控制场景的对象 */
    MouseController *mouseController;
    /** 专用的鼠标右键控制场景的对象 */
    RightMouseController *rightMouseController;

    /** 物体变换矩阵 WSY 20210205 */
    GLfloat *transformMatrix;
    /** 光照方向 WSY 20210205 */
    GLfloat *lightDirection;


    GLfloat *inverseMatrixNew;
    GLfloat *inverseTransposeMatrixNew;


    /** 顶点位置信息 */
    GLint positionAttribLocation;
    /** 法向量位置信息 */
    GLint normalAttribLocation;

    //模式信息
    GLint modeUniformLocation;
    /** 摄像机的矩阵(mat4) */
    GLint cameraMatrixUniformLocation;
    /** 物体变换矩阵(mat4) */
    GLint transformMatrixUniformLocation;
    /** 变换后的法向量位置信息(mat4) */
    GLint normalMatrixUniformLocation;
    /** 光的方向(vec3) */
    GLint reverseLightDirectionUniformLocation;
    /** 单一颜色(vec4) */
    GLint colorUniformLocation;
protected:
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void wheelEvent(QWheelEvent *event);
};

#endif // PIPEDISPLAYOPENGLWIDGET_H
